package com.demo.controller;

import com.demo.dto.ProjectDto;
import com.demo.pojo.Project;

import com.demo.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ProjectController
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/7 16:57
 * @Version 1.0
 **/
@Controller
@RequestMapping("project")
public class ProjectController {
    @Autowired
    ProjectService service;

//    @RequestMapping("findAllOneAndMany")
//    public List<Project> findAllOneAndMany(){
//        return service.findOneAndMany();
//    }

    @RequestMapping("findAllDto")
    @ResponseBody
    public List<ProjectDto> findAllDto(){
        List<ProjectDto> allDto = service.findAllDto();
        System.out.println(allDto);
        return  allDto;
    }

    @RequestMapping("updateProject")
    @ResponseBody
    public boolean updateProject( Project project){
        System.out.println("----------"+project);
        project.setUpdatetime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return service.updateProject(project);
    }

    @RequestMapping("deleteProject")
    @ResponseBody
    public boolean deleteProject(int pid){
        return service.deleteProjectById(pid);
    }

    @RequestMapping("insertProject")
    @ResponseBody
    public boolean insertProject(Project project){
        return service.insertProject(project);
    }

    @RequestMapping("findOne")
    @ResponseBody
    public Project findOneById(int pid){
        System.out.println(pid);
       return service.findOneById(pid);
    }
}
